﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKArchUtils.Utils;

namespace YJKRevitRampModule.Utils
{
	public class FillRegion
	{
		public List<EdgeInfo> EdgeLoop
		{
			get
			{
				return this.m_EdgeLoop;
			}
		}

		public List<bool> EdgeIsTransparent
		{
			get
			{
				return this.m_EdgeIsTransparent;
			}
		}

		public PenColor Color
		{
			get
			{
				return this.m_Color;
			}
		}

		public FillRegion(FillRegion rhs)
		{
			this.m_EdgeLoop = new List<EdgeInfo>();
			foreach (EdgeInfo rhs2 in rhs.m_EdgeLoop)
			{
				this.m_EdgeLoop.Add(new EdgeInfo(rhs2));
			}
			this.m_EdgeIsTransparent = rhs.m_EdgeIsTransparent;
			this.m_Color = rhs.Color;
		}

		public FillRegion(List<EdgeInfo> edgeLoop, PenColor color)
		{
			this.m_EdgeLoop = edgeLoop;
			this.m_EdgeIsTransparent = new List<bool>();
			for (int i = 0; i < edgeLoop.Count; i++)
			{
				this.m_EdgeIsTransparent.Add(false);
			}
			this.m_Color = color;
		}

		public void SetEdgeTransparent(int index)
		{
			this.m_EdgeIsTransparent[index] = true;
		}

		public bool IsNull()
		{
			return this.m_EdgeLoop == null;
		}

		public XYZ Normal()
		{
			XYZ xyz = this.m_EdgeLoop[0].EndPoint - this.m_EdgeLoop[0].StartPoint;
			return (this.m_EdgeLoop[this.m_EdgeLoop.Count - 1].StartPoint - this.m_EdgeLoop[this.m_EdgeLoop.Count - 1].EndPoint).CrossProduct(xyz).Normalize();
		}

		public void ScalingTransformation(Transform transform)
		{
			foreach (EdgeInfo edgeInfo in this.m_EdgeLoop)
			{
				XYZ startPoint = Geometry.TransformPoint(edgeInfo.StartPoint, transform);
				XYZ endPoint = Geometry.TransformPoint(edgeInfo.EndPoint, transform);
				edgeInfo.StartPoint = startPoint;
				edgeInfo.EndPoint = endPoint;
			}
		}

		public FillRegion Copy(Transform transform)
		{
			FillRegion fillRegion = new FillRegion(this);
			foreach (EdgeInfo edgeInfo in fillRegion.m_EdgeLoop)
			{
				XYZ startPoint = Geometry.TransformPoint(edgeInfo.StartPoint, transform);
				XYZ endPoint = Geometry.TransformPoint(edgeInfo.EndPoint, transform);
				edgeInfo.StartPoint = startPoint;
				edgeInfo.EndPoint = endPoint;
			}
			return fillRegion;
		}

		public double GetAverageZ()
		{
			double num = 0.0;
			foreach (EdgeInfo edgeInfo in this.m_EdgeLoop)
			{
				num += edgeInfo.StartPoint.Z;
			}
			num /= (double)this.m_EdgeLoop.Count;
			return num;
		}

		public double GetMaxZ()
		{
			double num = double.MinValue;
			foreach (EdgeInfo edgeInfo in this.m_EdgeLoop)
			{
				if (Geometry.LessThan(num, edgeInfo.StartPoint.Z))
				{
					num = edgeInfo.StartPoint.Z;
				}
			}
			return num;
		}

		private List<EdgeInfo> m_EdgeLoop;

		private List<bool> m_EdgeIsTransparent;

		private PenColor m_Color;
	}
}
